#include "widget.h"
#include "ui_widget.h"
#include <QTimer>
#include <QDateTime>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    //通过QTimer来计时，然后再通过绑定按钮的槽函数来对label进行修改
    QTimer* timer = new QTimer(this);
    //绑定槽函数
    connect(ui->pushButton_start,&QPushButton::clicked,[=]()
    {
       timer->start(1000);
    });
    connect(ui->pushButton_stop,&QPushButton::clicked,[=](){
        timer->stop();
    });
    connect(timer,&QTimer::timeout,[=](){
        QString str = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss");
        ui->label->setText(str);
    });
}

Widget::~Widget()
{
    delete ui;
}

